//
//  NSTextFieldWithLink.m
//  PostalTracker
//
//  Created by Aleksandr Batsuev on 1/31/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "NSTextFieldWithLink.h"
#import "PostalTrackerAppDelegate.h"

@implementation NSTextFieldWithLink

- (void) awakeFromNib
{
	[self setBordered:NO];
	[super awakeFromNib];
}

- (void) mouseDown:(NSEvent *)theEvent
{
	[controller showDetailedInfo:nil];
}

- (void)setController:(PostalTrackerAppDelegate*) value 
{
	controller = value;
}

- (float)calculateHeight:(NSString*)content
{
	float width = [self frame].size.width;
	
	NSTextStorage *textStorage = [[[NSTextStorage alloc] initWithString:content] autorelease];
	NSTextContainer *textContainer = [[[NSTextContainer alloc] initWithContainerSize: NSMakeSize(width, FLT_MAX)] autorelease];
	NSLayoutManager *layoutManager = [[[NSLayoutManager alloc] init] autorelease];
	
	[layoutManager addTextContainer:textContainer];
	[textStorage addLayoutManager:layoutManager];
	
	[textStorage addAttribute:NSFontAttributeName value:[self font] range:NSMakeRange(0, [textStorage length])];
	[textContainer setLineFragmentPadding:0.0];
	
	(void) [layoutManager glyphRangeForTextContainer:textContainer];
	return [layoutManager usedRectForTextContainer:textContainer].size.height;
}

@end
